from sqlalchemy import Column, Integer, Date, DateTime, Float, String
from sqlalchemy.sql import func
from backend.config.database import Base


class PredResult(Base):
    """预测结果表"""
    __tablename__ = "pred_result"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    dt = Column(Date, nullable=False, comment='预测日期')
    t_idx = Column(Integer, nullable=False, comment='时间点(1~96)')
    dtm = Column(DateTime, nullable=False, comment='预测时间')
    model = Column(String(32), nullable=False, comment='模型名称')
    pred_val = Column(Float, nullable=False, comment='预测负荷(MW)')
    created_at = Column(DateTime, default=func.now(), comment='生成时间')
    
    class Config:
        from_attributes = True


class ModelEval(Base):
    """模型评估表"""
    __tablename__ = "model_eval"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    model = Column(String(32), nullable=False, comment='模型名称')
    train_dt = Column(Date, nullable=False, comment='训练日期')
    mae = Column(Float, nullable=True, comment='平均绝对误差')
    rmse = Column(Float, nullable=True, comment='均方根误差')
    mape = Column(Float, nullable=True, comment='平均绝对百分比误差')
    r2 = Column(Float, nullable=True, comment='决定系数')
    max_err = Column(Float, nullable=True, comment='最大误差')
    created_at = Column(DateTime, default=func.now(), comment='评估时间')
    
    class Config:
        from_attributes = True